package com.collect.tanzania.zhiScene.zhiOrderReview.zhiFollow;

import android.content.Context;

import com.collect.tanzania.zhiBase.BasePresenter;
import com.collect.tanzania.zhiBase.BaseSubscriber;
import com.collect.tanzania.zhiBean.zhiReceive.ZHIRPhoneReviewListEntity;
import com.collect.tanzania.zhiBean.zhiSend.ZHISPhoneReviewFollowEntity;
import com.collect.tanzania.zhiBean.zhiSend.ZHISPhoneReviewMarkedEntity;
import com.collect.tanzania.zhiBean.zhiSend.ZHISendEntity;
import com.collect.tanzania.zhiNetApi.ZHIHttpApiProvider;
import com.collect.tanzania.zhiNetApi.ZHIHttpResponse;
import com.collect.tanzania.zhiScene.zhiOrderReview.zhiFollow.bean.ZHIROrderReviewDetailEntity;
import com.collect.tanzania.zhiScene.zhiOrderReview.zhiFollow.bean.ZHISOrderReviewDetailEntity;
import com.collect.tanzania.zhiUtils.RxSchedulers;

import javax.inject.Inject;

public class ZHIOrderReviewFollowPresenter extends BasePresenter<ZHIOrderReviewFollowContract.View> implements ZHIOrderReviewFollowContract.Presenter {

    @Inject
    public ZHIOrderReviewFollowPresenter() {

    }

    @Override
    public void showOrderReviewDetail(Context context, ZHISendEntity zhiSendEntity, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ZHIROrderReviewDetailEntity>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ZHIROrderReviewDetailEntity>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ZHIROrderReviewDetailEntity zhirOrderReviewDetailEntity = (ZHIROrderReviewDetailEntity) object;
                            mView.onShowOrderReviewDetail(zhirOrderReviewDetailEntity);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().showOrderReviewDetail(zhiSendEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }

    @Override
    public void handleOrderReview(Context context, ZHISOrderReviewDetailEntity zhisOrderReviewDetailEntity) {
        BaseSubscriber<ZHIHttpResponse> subscriber = new
                BaseSubscriber<ZHIHttpResponse>(context, this, true) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            mView.onHandleOrderReview();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().handleOrderReview(zhisOrderReviewDetailEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }
}
